/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;

import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

/**
 * Almosts tests of the HTML object. This is more of a demo/path checker.
 * @author J Patrick Davenport
 *
 */
public class HtmlTests {
	@Test
	public void seeAPage() throws IOException {
		final Html html = new Html();

		html.setPageTitle("An example page");
		final Div firstDiv = new Div();
		html.getBody()
				.setStyle("border: 1px solid black;")
				.addPageElement(firstDiv)
				.addPageElement(new A());

		firstDiv.addPageElement(new Content("This is my content, it could be DB created."))
				.addPageElement(new Image("/img/mypic.jpg", "why is alt text required?"))
				.addPageElement(new Text("person.firstName", "Patrick").setOnClick("alert('Sup, Mr. Man?');"))
				.addPageElement(new Hidden("ssn", "621225987"));

		final MockHttpServletRequest req = new MockHttpServletRequest();
		req.setContextPath("/MyApp");
		final MockHttpServletResponse res = new MockHttpServletResponse();

		html.render(req, res);

		System.out.println(res.getContentAsString());
	}

	@Test
	public void seeAPage2() throws IOException {
		final Html html = new Html();

		html.setPageTitle("An example page");
		final Div firstDiv = new Div();
		html.getBody()
				.setStyle("border: 1px solid black;")
				.addPageElement(firstDiv)
				.addPageElement(new A());

		firstDiv.addPageElement(new Content("This is my content, it could be DB created."))
				.addPageElement(new Image("/img/mypic.jpg", "why is alt text required?"))
				.addPageElement(new Text("person.firstName", "Patrick").setOnClick("alert('Sup, Mr. Man?');"))
				.addPageElement(new Hidden("ssn", "621225987"));

		final MockHttpServletRequest req = new MockHttpServletRequest();
		req.setContextPath("/MyApp");
		final MockHttpServletResponse res = new MockHttpServletResponse();

		html.render(req, res);

		System.out.println(res.getContentAsString());
	}

	@Test
	public void seeAPage3() throws IOException {
		final Html html = new Html();

		html.setPageTitle("An example page");
		final Div firstDiv = new Div();
		html.getBody()
				.setStyle("border: 1px solid black;")
				.addPageElement(firstDiv)
				.addPageElement(new A());

		firstDiv.addPageElement(new Content("This is my content, it could be DB created."))
				.addPageElement(new Image("/img/mypic.jpg", "why is alt text required?"))
				.addPageElement(new Text("person.firstName", "Patrick").setOnClick("alert('Sup, Mr. Man?');"))
				.addPageElement(new Hidden("ssn", "621225987"));

		final MockHttpServletRequest req = new MockHttpServletRequest();
		req.setContextPath("/MyApp");
		final MockHttpServletResponse res = new MockHttpServletResponse();

		html.render(req, res);

		System.out.println(res.getContentAsString());
	}

	@Test
	public void checkHead() {
		final Html h = new Html();
		final Head head = h.getHead();
		assertNotNull(head);

		final String title = "My Sweet Home";
		h.setPageTitle(title);
		assertEquals(title, h.getPageTitle());
	}

}
